<!DOCTYPE html>
<html>
<head>
    <title>接口测试</title>
    <meta charset="utf-8">
    <script src="jquery.js"></script>
    <script src="jquery.form.js"></script>
</head>
<body>
	<input id="api" type="text" placeholder="API根地址" value="http://127.0.0.1:7000" /> </br>
    <input id="url" type="text" placeholder="调用地址" /> </br>

    <textarea id="arg" style="width:100%;height:100px;" type="text" placeholder="参数"value="{}" >{
    "":"",
    "":"",
    "":"",
    "":""
}</textarea></br>
    <input id="call" type="button" value="调用" /> <br>
    <input id="arg1" style="width:100%" type="text"/> </br>
    <input id="call5" type="button" value="课程导出测试" /> <br>

    <div id="result"></div>
    <form id="fileForm"enctype="multipart/form-data">
        <input  style="width:160px" type="file"name="file" placeholder="参数" /> </br>
        <input id="call2" type="button" value="调用文件接口" onclick="click1()"/> <br>
    </form>
    <div id="result2"></div>
</body>
</html>
<script>

$("#call5").click(function(){
    window.open($("#api").val()+$("#url").val()+"?courseId="+$("#arg1").val());
});

$("#call").click(function(){
	var data;
	try {
		data = JSON.parse($("#arg").val());
	}catch(e) {
		$("#result").text("json书写错误");
		return;
	}
	$.ajax({url:$("#api").val()+$("#url").val(), method:"post", data:data, success: function(res){
		$("#result").text(JSON.stringify(res));
	}, error:function(XMLHttpRequest, textStatus){
		var status = XMLHttpRequest.status;
		$("#result").text("错误："+status);
	}});
});
function click1(){
    var data;
    try {
        data = JSON.parse($("#arg").val());
    }catch(e) {
        $("#result").text("json书写错误");
        return;
    }
    $("#fileForm").ajaxSubmit({
        url: $("#api").val()+$("#url").val(),
        type: "post",
        data:data,
        success: function (res, textStatus) {
            $("#result").text(JSON.stringify(res));
        },error:function(XMLHttpRequest, textStatus){
            var status = XMLHttpRequest.status;
            $("#result").text("错误："+status);
        }
    });
//	$.ajax({url:$("#api").val()+$("#url").val(), method:"post",  success: function(res){
//		$("#result").text(JSON.stringify(res));
//	}, error:function(XMLHttpRequest, textStatus){
//		var status = XMLHttpRequest.status;
//		$("#result").text("错误："+status);
//	}});
};
</script>